asm
  ld sp,$FFEF
  end asm

#include "./library/pacmandelay.bas"
#include "./library/smsrnd.bas"
#include "./library/arcadetypeface.bas"

dim eee as uinteger at $E012
dim seed as uinteger at $E014
dim ee0 as uinteger at $E010
dim ee1 as uinteger at $E01A
dim ee2 as uinteger at $E016
dim ee3 as uinteger at $E018
dim ecsp as ubyte at $E01C
dim ecsq as ubyte at $E01E
dim ex0 as uinteger at $E020
dim ey0 as uinteger at $E022
dim ej0 as uinteger at $E024
dim ej1 as uinteger at $E026
dim i5 as uinteger at $E028
dim i4 as uinteger at $E02A


sub brodputchar(txpos as uinteger,typos as uinteger, tchar as uinteger,tattr as ubyte,ttdp as uinteger):
  dim tln as uinteger at $E000
  dim tdq as uinteger at $E002
  tdq=(txpos)+((typos band 7)*32)+((int(typos/8))*2048)  ' +(i3*256)
  for tln=0 to 7
    poke $4000+tdq+(tln*256),peek(ttdp+((tchar band $FF)*8)+tln)
    next
  poke $5800+(txpos)+(typos*32),tattr
  end sub


for i5=0 to 23
  for i4=0 to 31
    ee2=seed:seed=smsrnd(seed)
    ee2=seed:seed=smsrnd(seed)
    brodputchar(i4,i5,128+(ee2 mod 9),seed band 127,@typeface01)
    next:next

for i5=0 to 15
  for i4=0 to 15
    brodputchar(i4+15,i5+7,i4+(i5*16),64+(1*8)+5,@typeface01)
    next:next

ex0=4
ey0=5
ee0=0
do

brodputchar(ex0,ey0,ee0 band 127,(7*8)+0,@typeface01)

brodputchar(5,1,48+(ee0 mod 10),(7*8)+0,@typeface01)
brodputchar(4,1,48+(int(ee0/10) mod 10),(7*8)+0,@typeface01)
brodputchar(3,1,48+(int(ee0/100) mod 10),(7*8)+0,@typeface01)
brodputchar(2,1,48+(int(ee0/1000) mod 10),(7*8)+0,@typeface01)
brodputchar(1,1,48+(int(ee0/10000) mod 10),(7*8)+0,@typeface01)

ee1=in($1F) bxor $FF
brodputchar(3,2,48+(ee1 mod 10),(7*8)+0,@typeface01)
brodputchar(2,2,48+(int(ee1/10) mod 10),(7*8)+0,@typeface01)
brodputchar(1,2,48+(int(ee1/100) mod 10),(7*8)+0,@typeface01)

ex0=ex0-((ee1 band 1)/1)+((ee1 band 2)/2)
ey0=ey0-((ee1 band 4)/4)+((ee1 band 8)/8)

ee0=ee0+1
loop




do

for eee=$4000 to $5AFF
  seed=smsrnd(seed)
  poke eee,seed
  next

loop





'static ADDRESS_MAP_START (spectrum_mem, AS_PROGRAM, 8, photon2_state )
'AM_RANGE(0x0000, 0x3fff) AM_ROMBANK("bank1")
'AM_RANGE(0x4000, 0x5aff) AM_RAM AM_SHARE("spectrum_vram")
'AM_RANGE(0x5b00, 0xffff) AM_RAM
'ADDRESS_MAP_END


'static ADDRESS_MAP_START (spectrum_io, AS_IO, 8, photon2_state )
'ADDRESS_MAP_GLOBAL_MASK(0xff)
'AM_RANGE(0x1f, 0x1f) AM_READ_PORT("JOY")
'AM_RANGE(0x5b, 0x5b) AM_READ_PORT("COIN") AM_WRITE(photon2_misc_w)
'AM_RANGE(0x7a, 0x7a) AM_WRITE(photon2_membank_w)
'AM_RANGE(0x7b, 0x7b) AM_WRITENOP // unknown write
'AM_RANGE(0x7e, 0x7e) AM_WRITE(photon2_membank_w)
'AM_RANGE(0xfe, 0xfe) AM_READWRITE(photon2_fe_r, photon2_fe_w)
'ADDRESS_MAP_END







